package com.ileaf.java8.gui;

import com.ileaf.chromosphere.UiMain;

import javax.swing.*;
import java.awt.*;

/**
 * @author Lianlb
 * @since 2019-11-25 14:56
 */
public class DoubleColorBall extends JFrame implements Function {
    private static final long serialVersionUID = 959865346514773378L;

    private JPanel panel;
    private JButton start;
    private JTextPane redTxt;
    private JTextPane blueTxt;
    private JButton homeButton;
    private JLabel redLabel;
    private JLabel blueLabel;
    private JPanel upPanel;

    DoubleColorBall(String title) throws HeadlessException {
        super(title);
        setContentPane(panel);
        setMinimumSize(new Dimension(600, 400));
        setLocation(300, 100);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        createUIComponents();
    }

    @Override
    public void createUIComponents() {
        redTxt.setForeground(Color.RED);
        blueTxt.setForeground(Color.BLUE);
        addComponentsAction();
    }

    @Override
    public void addComponentsAction() {
        start.addActionListener(event -> {
            String redSphere = UiMain.getRedSphere();
            String blueSphere = UiMain.getBlueSphere();
            redTxt.setText(redSphere.replace("[", "").replace("]", ""));
            blueTxt.setText(blueSphere);
        });
        homeButton.addActionListener(event -> {
            dispose();
            // 打开主窗口
            Home home = new Home("系统主页");
            home.pack();
            home.setVisible(true);
        });

    }
}
